import javax.telephony.*;
import javax.telephony.events.*;
// import MyOutCallObserver; 
public class OutCall {
	public static final void main(String args[]) {

		/*
		 * Create a provider by first obtaining the default implementation of
		 * JTAPI and then the default provider of that implementation.
		 */
		Provider myprovider = null;
		try {
			JtapiPeer peer = JtapiPeerFactory
					.getJtapiPeer("net.xtapi.XJtapiPeer");
			myprovider = peer.getProvider("MSTAPI");
		} catch (Exception excp) {
			System.out.println("Can't get Provider: " + excp.toString());
			System.exit(0);
		}

		/*
		 * We need to get the appropriate objects associated with the
		 * originating side of the telephone call. We ask the Address for a list
		 * of Terminals on it and arbitrarily choose one.
		 */
		Address origaddr = null;
		Terminal origterm = null;
		try {
			origaddr = myprovider.getAddress("0");

			/* Just get some Terminal on this Address */
			Terminal[] terminals = origaddr.getTerminals();
			if (terminals == null) {
				System.out.println("No Terminals on Address.");
				System.exit(0);
			}
			origterm = terminals[0];
		} catch (Exception excp) {
			System.out.println("no terminal: " + excp.toString());
			System.exit(0);
			// Handle exceptions;
		}

		/*
		 * Create the telephone call object and add an observer.
		 */
		Call mycall = null;
		try {
			mycall = myprovider.createCall();
			mycall.addObserver(new MyOutCallObserver());
		} catch (Exception excp) {
			// Handle exceptions
		}

		/*
		 * Place the telephone call.
		 */
		try {
			Connection c[] = mycall.connect(origterm, origaddr, "25551212");
		} catch (Exception excp) {
			// Handle all Exceptions
		}
	}
}
